<template>
	<view>
		<view v-for="(item,index) in goodsListData" :key="index" @click="gotoDetail(item)">
		    <my-goods :goods="item"></my-goods>
		</view>
	</view>
</template> 

<script>
	export default {
		data() {
			return {
				loading:false,
				goodsListData:[],
				total:0,
				queryObj:{
					query:'',
					cid:'',
					pagenum:1,
					pagesize:10//每页条数
				}
			};
		},
		
		 onPullDownRefresh(){
			 this.queryObj.pagenum = 1,
			 this.total=0,
			 this.loading = false,
			 this.goodsListData =[]
			 this.getgoodsList(()=>uni.stopPullDownRefresh())
		  },
		onReachBottom(){
			//判断是否还有下一页
			if(this.queryObj.pagenum * this.queryObj.pagesize >= this.total)return uni.$showMsg('已经触底了')
			if(this.isLoading)return;
			this.queryObj.pagenum+=1
			this.getgoodsList()
		},
		onLoad(option){
			const {query,cid} = option
			this.queryObj.query= query ||''
			this.queryObj.cid = cid||""
			this.getgoodsList()
		}, 
		methods:{
			gotoDetail(item){
				uni.navigateTo({
					url:'/subpkg/goods_detail/goods_detail?goods_id='+item.goods_id
				})
			},
			async getgoodsList(callback){
				  this.isLoading = true
				  const {data:res} =await uni.$http.get('/api/public/v1/goods/search',this.queryObj)
				  if(res.meta.status !==200) return uni.$showMsg()
				  this.goodsListData = [...this.goodsListData,...res.message.goods]
				  this.total = res.message.total
				  this.isLoading = false
				  callback&&callback()
			}
		}
	}
</script>

<style lang="scss">

</style>
